package xyz.wanhongtao.smtpclient.object.vo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import xyz.wanhongtao.smtpclient.object.properties.ResultEnum;

/**
 * @author wanghongtao <wanghongtao05@kuaishou.com>
 * Created on 2023-07-03
 */
@NoArgsConstructor
@AllArgsConstructor
@Data
public class Result<T> {
    Integer code;

    String message;

    T data;

    public static Result<?> success () {
        return new Result<>(ResultEnum.SUCCESS.getCode(), ResultEnum.SUCCESS.getMessage(), null);
    }

    public static<T> Result<T> success (T data) {
        return new Result<>(ResultEnum.SUCCESS.getCode(), ResultEnum.SUCCESS.getMessage(), data);
    }

    public static<T> Result<?>  error (ResultEnum resultEnum) {
        return new Result<T>(resultEnum.getCode(), resultEnum.getMessage(), null);
    }

    public static <T> Result<T> error () {
        return new Result<T>(ResultEnum.ERROR.getCode(), ResultEnum.ERROR.getMessage(), null);
    }

    public static <T> Result<T> error (Integer code, String message) {
        return new Result<T>(code, message, null);
    }

}
